package com.artPreter.service.impl;


import com.artPreter.mapper.ContentTagMapper;
import com.artPreter.pojo.ContentTag;
import com.artPreter.service.IContentTagService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 模块标签表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-11-26
 */
@Service
public class ContentTagServiceImpl extends ServiceImpl<ContentTagMapper, ContentTag> implements IContentTagService {

    @Override
    public IPage<ContentTag> getPage(Integer currentPage, Integer size, ContentTag contentTag) {
        IPage<ContentTag> contentTagIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<ContentTag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ContentTag::getStatus,1);
        if(contentTag.getContentId()==null||contentTag.getContentId().equals("")){
            return contentTagIPage;
        }else{
            queryWrapper.eq(ContentTag::getContentId,contentTag.getContentId());
        }
        contentTagIPage = this.baseMapper.selectPage(contentTagIPage, queryWrapper);
        return contentTagIPage;
    }

    @Override
    public void add(ContentTag contentTag) {
        contentTag.setStatus(1);
        // 生成UUID并设置到实体对象中
        String uuid = UUID.randomUUID().toString();
        contentTag.setTagId(uuid);
        this.baseMapper.insert(contentTag);
    }

    @Override
    public void edit(ContentTag contentTag) {
        this.baseMapper.updateById(contentTag);
    }

    @Override
    public void delete(ContentTag contentTag) {
        this.baseMapper.deleteById(contentTag);
    }

    @Override
    public List<ContentTag> getList(ContentTag contentTag) {
        LambdaQueryWrapper<ContentTag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ContentTag::getStatus,1);
        List<ContentTag> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }
}
